/*
 * Copyright 2004-2006 公司名
 * 本软件及其所有拷贝的名称，与光盘上或本软件中注明的公司同在。
 * 本软件及文档享有版权，并受国家版权法及国际协约条款的保护。
 * 您不可以从本软件中去掉其版权声明；并保证为本软件的拷贝（本部或部分）复制版权声明。
 * 您同意制止以任何形式非法拷贝本软件及文档。
 * 版权信息参见：
 *      http://www.companyname.cn/licenses
 */

package com.companyname.common.sysframe.view.foreveryone;

import java.util.List;
import java.util.Vector;

import org.apache.log4j.Logger;

import com.companyname.common.base.define.FontLayOut;
import com.companyname.common.base.model.BaseObject;
import com.companyname.common.base.web.view.AddFuncButton;
import com.companyname.common.base.web.view.BaseObjectListTemplet;
import com.companyname.common.base.web.view.ConfigColumnFuncButton;
import com.companyname.common.base.web.view.DelFuncButton;
import com.companyname.common.base.web.view.ExportFuncButton;
import com.companyname.common.base.web.view.FuncItem;
import com.companyname.common.base.web.view.Item;
import com.companyname.common.base.web.view.Item4ChangePri;
import com.companyname.common.base.web.view.Item4CheckBox;
import com.companyname.common.base.web.view.Item4Remark;
import com.companyname.common.base.web.view.PrintFuncButton;
import com.companyname.common.base.web.view.QueryFuncButton;
import com.companyname.common.base.web.view.Title4CheckBox;
import com.companyname.common.base.web.view.Title4Remark;
import com.companyname.common.base.web.view.Title4Sort;
import com.companyname.common.base.web.view.Title4SortPri;
import com.companyname.common.base.web.view.UpdateFuncButton;
import com.companyname.common.sysframe.define.UserStatus;
import com.companyname.common.sysframe.model.User;
import com.companyname.common.sysframe.util.CompanyNameSysFrameException;

/**
 * <p>Title: 人员结果列表 </p>
 * <p>Description: 人员结果列表 User </p>
 * <p>Copyright: Copyright (c) 2004-2006</p>
 * <p>Company: 公司名</p>
 * @ $Author: 作者名 $
 * @ $Date: 创建日期 $
 * @ $Revision: 1.0 $
 * @ created in 创建日期
 *
 */

public class UserList4EveryOne extends BaseObjectListTemplet
{
        static Logger logger = Logger.getLogger(UserList4EveryOne.class);

        /** 功能按钮区 */
        public List getButtons(String contextPath)
        {
                List fbs = new Vector();
                fbs.add(new AddFuncButton());
                fbs.add(new UpdateFuncButton());
                fbs.add(new DelFuncButton());
                fbs.add(new UpdateFuncButton("设密码","resetPW()"));
                fbs.add(new UpdateFuncButton("加解锁","lockUnlock()"));
                fbs.add(new QueryFuncButton());
                fbs.add(new ExportFuncButton());
                fbs.add(new PrintFuncButton());
                fbs.add(new ConfigColumnFuncButton());
                return fbs;
        }

        /** 功能切换区 */
        public List getChanges(String contextPath)
        {
                List fis = new Vector();
                fis.add(new FuncItem("人员",true));
                return fis;
        }

        /** 明细标题区 */
        public List getTitles(String contextPath)
        {
                List titles = new Vector();
                titles.add(new Title4CheckBox());
                titles.add(new Title4Sort("帐号","user.account"));
                titles.add(new Title4Sort("姓名","(user.familyName + user.givenName)"));
                titles.add(new Title4Sort("状态","user.status").setPrinted(false));
                titles.add(new Title4SortPri());
                titles.add(new Title4Sort("生日","user.birthday"));
                titles.add(new Title4Sort("地址","user.address"));
                titles.add(new Title4Sort("email","user.email"));
                titles.add(new Title4Sort("电话","user.phone"));
                titles.add(new Title4Sort("手机","user.mobile"));
                titles.add(new Title4Sort("个人主页","user.homeSite"));
                titles.add(new Title4Sort("密码有效期","user.pwLimtDate"));
                titles.add(new Title4Sort("帐号有效期","user.idLimtDate"));
                titles.add(new Title4Sort("密码错误次数","user.pwErrorNum"));
                titles.add(new Title4Sort("密码错误锁定帐号次数","user.pwErrorLock"));
                titles.add(new Title4Remark());
                return titles;
        }

        /** 明细区 */
        public List getItems(String contextPath,BaseObject model)
        {
                User user = (User)model;
                List items = new Vector();
                items.add(new Item4CheckBox(user.getId()));
                items.add(new Item(user.getAccount()));
                items.add(new Item(user.getName()));
                switch(user.getStatus())
                {
                        case UserStatus.VALID:
                        {
                                items.add(new Item(user.getStatusName()).setLength(2)
                                                                        .setXLayOut(FontLayOut.CENTER)
                                                                        .setPrinted(false));
                                break;
                        }
                        case UserStatus.LOCKED:
                        {
                                items.add(new Item("<font color='red'>"
                                                   + user.getStatusName()
                                                   + "</font>").setLength(2)
                                                               .setXLayOut(FontLayOut.CENTER)
                                                               .setPrinted(false));
                                break;
                        }
                        default:
                        {
                                throw new CompanyNameSysFrameException("列表不支持显示该状态(" + user.getStatus() + ")的用户");
                        }
                }
                
                items.add(new Item4ChangePri(model));
                items.add(new Item(user.getFormatedBirthday()).setLength(5));
                items.add(new Item(user.getAddress()));
                items.add(new Item(user.getEmail()));
                items.add(new Item(user.getPhone()));
                items.add(new Item(user.getHomeSite()));
                items.add(new Item(user.getMobile()));
                items.add(new Item(user.getFormatedPwLimtDate()).setLength(5));
                items.add(new Item(user.getFormatedIdLimtDate()).setLength(5));
                items.add(new Item(user.getPwErrorNum()));
                items.add(new Item(user.getPwErrorLock()));
                items.add(new Item4Remark(user.getRemark()));
                return items;
        }

}
